<?php
/**
 * Created by PhpStorm.
 * User: kongqi
 * Date: 2019/10/4
 * Time: 13:16
 */

namespace App\Plugin\HostServer\Models;

class PnHostSvSystemGoods extends HostServerBase
{
    public static function add($data, $goods_id)
    {

        if (empty($data)) {
            return false;
        }
        $arr = [];
        foreach ($data as $k => $v) {
            if (empty($v)) {
                continue;
            }
            foreach ($v['sub'] as $k2 => $v2) {
                $arr[] = [
                    'category_id' => $k,
                    'sub_id' => $v2,
                    'good_id' => $goods_id
                ];
            }
        }
        if(empty($arr)){
            return false;
        }

        //删除之前的
        self::where('good_id',$goods_id)->delete();
        $r=self::insert($arr);
        return $r;

    }
}